<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="net.sf.ehcache.Element,net.sf.ehcache.CacheManager,
                 java.text.SimpleDateFormat,
                 java.util.Date,
                 net.sf.ehcache.Cache" %>
<html>
<head>
<title>EhCache管理</title>            
<!-- HTTP 1.1 -->
<meta http-equiv="Cache-Control" content="no-store"/>
<!-- HTTP 1.0 -->
<meta http-equiv="Pragma" content="no-cache"/>
<!-- Prevents caching at the Proxy Server -->
<meta http-equiv="Expires" content="0"/>

<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>


<table  width=95% align=center>
<tr>
<td>
<td align=right>
<a href='./index.jsp'>EhCache首页</a>&nbsp;|&nbsp;
<a href='javascript:window.location.reload()'>刷新</a>&nbsp;|&nbsp;
<a href='javascript:history.go(-1)'>后退</a>&nbsp;|&nbsp;
</td>
</tr>
</table>

<font color=red size=4><b>Cache对象管理</b></font>

<%
    SimpleDateFormat sdf =new SimpleDateFormat("yyyy/MM/dd HH:mm:ss SSS");
    String cacheName=request.getParameter("cacheName");
    String className = request.getParameter("className");

    String key=request.getParameter("key");

    Element element= null;
    Cache cache = CacheManager.getInstance().getCache(cacheName);
    //out.println("memo size = " + cache.calculateInMemorySize() );
	element = cache.get(key);
   

    try{

String method = request.getParameter("method");

if(method != null && method.equals("remove")){
	cache.remove(element.getKey());
	out.println(cacheName + " key [ "+ key +" ] has  removed .");

} else {
		if(element == null) {
%>
<table width="98%" border="0" cellspacing="1" cellpadding="5"  align="center" >
<tr class=tr2>
<td>cacheName=<%=cacheName%></td>
<td>cacheKey=<%=key%></td>
<td>element is null .</td>
</tr>
</table>
<%			
		}else {


%>
<table width="98%" border="0" cellspacing="1" cellpadding="5"  align="center" >
<tr class=tr2>
<td>cacheName=<%=cacheName%></td>
<td>cacheKey=<%=key%></td>
<td>HitCount=<%=element.getHitCount()%></td>
</tr>
<tr class=tr1>
<td>CreationTime=<%=sdf.format(new Date(element.getCreationTime()))%></td>
<td>LastAccessTime=<%=sdf.format(new Date(element.getLastAccessTime()))%></td>
<td> </td>
</tr>
</table>
<font color=red><b>内容：</b></font><br>
<%

    try{
            out.println((String)element.getValue());
    }catch(java.lang.ClassCastException ce){
        out.println(element.getValue().toString());
    }catch(java.lang.OutOfMemoryError oe){
        out.println("OutOfMemoryError :" + oe.getMessage());
    }

		}
}
    }catch(Exception e){
        System.out.println("showCacheElement Exception :" + e.getMessage());
    }
%>
